package com.golden.order02.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.golden.order02.dao.OrderHisSessionMapper;
import com.golden.order02.domain.OrderHisSessionDO;
import com.golden.order02.domain.ResultDO;
import com.golden.order02.entity.OrderHisSession;
import com.golden.order02.query.OrderHisSessionExample;

@Service
public class OrderHisSessionServiceImpl implements OrderHisSessionService{
	@Autowired
	OrderHisSessionMapper orderHisSessionMapper;
	
	public ResultDO<OrderHisSessionDO> get( Integer id){
		
		ResultDO<OrderHisSessionDO> result=new ResultDO<OrderHisSessionDO>();
		BaseServiceImpl<OrderHisSessionDO,OrderHisSession> bi=new BaseServiceImpl<>();
		OrderHisSessionDO oo=new OrderHisSessionDO();
		
		try {
			OrderHisSession selectByPrimaryKey = orderHisSessionMapper.selectByPrimaryKey(id);
			OrderHisSessionDO t = bi.getT(selectByPrimaryKey, oo);
			result.setData(t);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_QUERY_ERROR);
			result.setErrorMsg(ResultDO.ORDER_QUERY_MSG_ERROR);
		}
		return result;
	}
	
	public ResultDO<List<OrderHisSessionDO>> query( OrderHisSessionExample example){
		ResultDO<List<OrderHisSessionDO>> result=new ResultDO<List<OrderHisSessionDO>>();
		BaseServiceImpl<OrderHisSessionDO,OrderHisSession> bi=new BaseServiceImpl<>();
		OrderHisSessionDO oo=new OrderHisSessionDO();
		try {
			List<OrderHisSession> selectByExample = orderHisSessionMapper.selectByExample(example);
			List<OrderHisSessionDO> tList = bi.getTList(selectByExample, oo);
			result.setData(tList);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_QUERY_ERROR);
			result.setErrorMsg(ResultDO.ORDER_QUERY_MSG_ERROR);
		}
		return result;
	}
	
	public ResultDO<OrderHisSessionDO> add(OrderHisSessionDO beanDO){
		
		ResultDO<OrderHisSessionDO> result=new ResultDO<OrderHisSessionDO>();
		BaseServiceImpl<OrderHisSession, OrderHisSessionDO> bi=new BaseServiceImpl<>();
		OrderHisSession oi=new OrderHisSession();
		OrderHisSession t = bi.getT(beanDO, oi);
		try {
			int insert = orderHisSessionMapper.insert(t);
			if(insert<=0) {
				throw new Exception();
			}
			beanDO.setId(t.getId());
			result.setData(beanDO);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_ADD_ERROR);
			result.setErrorMsg(ResultDO.ORDER_ADD_MSG_ERROR);
		}
		return result;
	}
	
	public ResultDO<Integer> delete( Integer id){
		
		ResultDO<Integer> result=new ResultDO<Integer>();
		try {
			int deleteByPrimaryKey = orderHisSessionMapper.deleteByPrimaryKey(id);
			if(deleteByPrimaryKey<=0) {
				throw new Exception();
			}
			result.setData(id);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_DELETE_ERROR);
			result.setErrorMsg(ResultDO.ORDER_DELETE_MSG_ERROR);
		}
		return result;
	}
	
	public ResultDO<OrderHisSessionDO> modify( OrderHisSessionDO beanDO){
		
		ResultDO<OrderHisSessionDO> result=new ResultDO<OrderHisSessionDO>();
		BaseServiceImpl<OrderHisSession, OrderHisSessionDO> bi=new BaseServiceImpl<>();
		OrderHisSession oi=new OrderHisSession();
		OrderHisSession t = bi.getT(beanDO, oi);
		try {
			int insert = orderHisSessionMapper.updateByPrimaryKeySelective(t);
			if(insert<=0) {
				throw new Exception();
			}
			result.setData(beanDO);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_MODIFY_ERROR);
			result.setErrorMsg(ResultDO.ORDER_MODIFY_MSG_ERROR);
		}
		return result;
	}
}
